package com.wgo.precise.server.pdf;

import com.lowagie.text.Document;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;

public class EndOfPage extends PdfPageEventHelper {

	private String endOfPageText = "";
	
	public String getEndOfPageText() {
		return endOfPageText;
	}

	public void setEndOfPageText(String endOfPageText) {
		this.endOfPageText = endOfPageText;
	}

	public void onEndPage(PdfWriter writer, Document document) {
		try {
			Rectangle page = document.getPageSize();
			PdfPTable foot = new PdfPTable(2);
			foot.addCell(endOfPageText);
			foot.addCell("                                          Page " + document.getPageNumber());
			foot.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin());
			foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent());
		} catch (Exception e) {
			throw new ExceptionConverter(e);
		}
	}
}
